package org.dtrd.modules.drug.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.dtrd.base.BaseController;
import org.dtrd.common.api.vo.Result;
import org.dtrd.common.aspect.annotation.AutoLog;
import org.dtrd.modules.drug.entity.bean.DrugCategoryDetail;
import org.dtrd.modules.drug.entity.bean.DrugCategoryInfo;
import org.dtrd.modules.drug.entity.request.DrugCategoryListRequest;
import org.dtrd.modules.drug.service.IDtrdExtEmsYwDrugCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static org.dtrd.common.constant.CommonConstant.*;
import static org.dtrd.config.system.SystemState.ResponseState.STATE_OPERATION_FAILURE;
import static org.dtrd.config.system.SystemState.ResponseState.STATE_PARAMS_ERROR;

/**
 * @author qr
 * @date 2021/12/2 14:20
 */
@Api(tags = "药品库")
@RestController
@RequestMapping("/100/13/")
public class DrugCategoryController extends BaseController {

    @Autowired
    private IDtrdExtEmsYwDrugCategoryService drugCategoryService;


    @ApiOperation("获取药品栏目列表")
    @GetMapping("1001301")
    @AutoLog(value = "获取药品栏目列表", operateType = OPERATE_TYPE_QUERY)
    public Result<?> getDrugColumnList(@RequestBody DrugCategoryListRequest request){
        List<DrugCategoryInfo> drugCategoryInfoList = drugCategoryService.getDrugColumnList(request);
        return Result.OK(drugCategoryInfoList);
    }


    @ApiOperation(value = "获取药品分类列表", notes = "pid == 0 的是就算是分类")
    @GetMapping("1001308")
    @AutoLog(value="获取药品分类列表", operateType = OPERATE_TYPE_QUERY)
    public Result<?> getDrugCategoryList(){
        List<DrugCategoryInfo> drugCategoryInfoList = drugCategoryService.getDrugCategoryList();
        return Result.OK(drugCategoryInfoList);
    }


    @ApiOperation("获取药品分类详情")
    @GetMapping("1001309")
    @AutoLog(value="获取药品分类详情", operateType = OPERATE_TYPE_QUERY)
    public Result<?> getDrugCategoryDetail(@RequestParam Integer drugCategoryId){
        DrugCategoryDetail drugCategory = drugCategoryService.getDrugCategory(drugCategoryId);
        return Result.OK(drugCategory);
    }


    @ApiOperation("删除药品分类")
    @DeleteMapping("1001306")
    @AutoLog(value="删除药品分类", operateType = OPERATE_TYPE_DELETE)
    public Result<?> removeDrugCategory(@RequestParam Integer dataId){
        if (isIntParamInvalid(dataId)) {
            return error(STATE_PARAMS_ERROR);
        }
        boolean result = drugCategoryService.removeDrugCategory(dataId);
        return result ? Result.OK() : error(STATE_OPERATION_FAILURE);
    }


    @ApiOperation("更新或修改药品分类信息")
    @PostMapping("1001307")
    @AutoLog(value="更新或修改药品分类信息", operateType = OPERATE_TYPE_SAVE_OR_UPDATE)
    public Result<?> saveOrUpdateDrugCategory(@RequestBody DrugCategoryDetail drugCategoryDetail){
        boolean result = drugCategoryService.saveOrUpdateDrugCategory(drugCategoryDetail);
        return result ? Result.OK() : error(STATE_OPERATION_FAILURE);
    }
}
